package teamproject.graphEditor;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;

import javax.swing.JFrame;
import javax.swing.JMenuItem;

import teamproject.graphEditor.dialogs.RenamePDEEdgeDialog;
import edu.uci.ics.jung.visualization.VisualizationViewer;

@SuppressWarnings("serial")
public class RenamePDEEdgeMenuItem<E> extends JMenuItem implements
		PDEEdgeMenuListener<E>, MenuCoordListener {

	private E edge;
	@SuppressWarnings("rawtypes")
	protected VisualizationViewer vv;
	private Point2D point;
	private JFrame frame;
	private GraphEditor graphEditor;

	public RenamePDEEdgeMenuItem(JFrame frame, GraphEditor graphEditor) {
		super("Kante umbenennen...");
		this.frame = frame;
		this.graphEditor = graphEditor;
		this.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				refreshGUI();
			}
		});
	}

	/**
	 * Refresh gui.
	 */
	public void refreshGUI() {
		RenamePDEEdgeDialog dialog = new RenamePDEEdgeDialog(frame,
				(PDEEdge) edge, graphEditor);
		dialog.setLocation((int) point.getX() + frame.getX(),
				(int) point.getY() + frame.getY());
		dialog.setVisible(true);
	}

	@SuppressWarnings("rawtypes")
	@Override
	public void setEdgeAndView(E e, VisualizationViewer vv) {
		this.edge = e;
		this.vv = vv;
	}

	@Override
	public void setPoint(Point2D point) {
		this.point = point;
	}

}
